package com.health.healthSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.health.common.annotation.Log;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.common.enums.BusinessType;
import com.health.healthSys.domain.InfoComment;
import com.health.healthSys.service.IInfoCommentService;
import com.health.common.utils.poi.ExcelUtil;
import com.health.common.core.page.TableDataInfo;
import com.health.common.utils.SecurityUtils;

/**
 * 资讯评论Controller
 * 
 * @author maple
 * @date 2025-03-24
 */
@RestController
@RequestMapping("/healthSys/comment")
public class InfoCommentController extends BaseController
{
    @Autowired
    private IInfoCommentService infoCommentService;

    /**
     * 查询资讯评论列表
     */
    @PreAuthorize("@ss.hasPermi('healthSys:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfoComment infoComment)
    {
        startPage();
        List<InfoComment> list = infoCommentService.selectInfoCommentList(infoComment);
        return getDataTable(list);
    }

    /**
     * 导出资讯评论列表
     */
    @PreAuthorize("@ss.hasPermi('healthSys:comment:export')")
    @Log(title = "资讯评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoComment infoComment)
    {
        List<InfoComment> list = infoCommentService.selectInfoCommentList(infoComment);
        ExcelUtil<InfoComment> util = new ExcelUtil<InfoComment>(InfoComment.class);
        util.exportExcel(response, list, "资讯评论数据");
    }

    /**
     * 获取资讯评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('healthSys:comment:query')")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") String commentId)
    {
        return success(infoCommentService.selectInfoCommentByCommentId(commentId));
    }

    /**
     * 新增资讯评论
     */
    @PostMapping
    public AjaxResult add(@RequestBody InfoComment infoComment)
    {
        // 设置当前登录用户信息
        infoComment.setUserId(SecurityUtils.getUserId().toString());
        return toAjax(infoCommentService.insertInfoComment(infoComment));
    }

    /**
     * 修改资讯评论
     */
    @PreAuthorize("@ss.hasPermi('healthSys:comment:edit')")
    @Log(title = "资讯评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoComment infoComment)
    {
        return toAjax(infoCommentService.updateInfoComment(infoComment));
    }

    /**
     * 删除资讯评论
     */
    @PreAuthorize("@ss.hasPermi('healthSys:comment:remove')")
    @Log(title = "资讯评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable String[] commentIds)
    {
        return toAjax(infoCommentService.deleteInfoCommentByCommentIds(commentIds));
    }

    /**
     * 审核评论
     */
    @PreAuthorize("@ss.hasPermi('healthSys:comment:audit')")
    @Log(title = "评论审核", businessType = BusinessType.UPDATE)
    @PutMapping("/audit/{commentId}")
    public AjaxResult audit(@PathVariable("commentId") String commentId, @RequestBody InfoComment infoComment)
    {
        return toAjax(infoCommentService.auditComment(commentId, infoComment.getStatus(), infoComment.getAuditRemark()));
    }

    /**
     * 点赞评论
     */
    @PostMapping("/like/{commentId}")
    public AjaxResult like(@PathVariable("commentId") String commentId)
    {
        return toAjax(infoCommentService.likeComment(commentId));
    }

    /**
     * 取消点赞评论
     */
    @PostMapping("/unlike/{commentId}")
    public AjaxResult unlike(@PathVariable("commentId") String commentId)
    {
        return toAjax(infoCommentService.unlikeComment(commentId));
    }

    /**
     * 举报评论
     */
    @PostMapping("/report/{commentId}")
    public AjaxResult report(@PathVariable("commentId") String commentId, @RequestBody InfoComment infoComment)
    {
        return toAjax(infoCommentService.reportComment(commentId, infoComment.getReportReason()));
    }

    /**
     * 获取评论树形结构
     */
    @GetMapping("/tree/{infoId}")
    public AjaxResult getCommentTree(@PathVariable("infoId") String infoId)
    {
        return success(infoCommentService.getCommentTree(infoId));
    }

    /**
     * 获取待审核评论列表
     */
    @PreAuthorize("@ss.hasPermi('healthSys:comment:audit')")
    @GetMapping("/pending")
    public TableDataInfo getPendingAuditList(InfoComment infoComment)
    {
        startPage();
        List<InfoComment> list = infoCommentService.selectPendingAuditList(infoComment);
        return getDataTable(list);
    }
}
